package com.zhiyume.exception;

/**
 * 异常处理工具类
 * */
public class ExceptionUtils {
  
  /**
   * 封装异常信息
   * */
  public static String buildMessage(String message, Throwable cause) {
        if (cause != null) {
            StringBuilder buf = new StringBuilder();
            if (message != null) {
                buf.append(message).append("; ");
            }
            buf.append("nested exception is ").append(cause);
            return buf.toString();
        } else {
            return message;
        }
    }
  
  
	  /**
	 * 方法说明：将异常类转换成字符串
	 * @param  e 传递的异常参数
	 * @return String 返回异常信息
	 * */
	 public static String getExceptionMsg(Throwable e){
      StringBuffer strBuf = new StringBuffer();
	  StackTraceElement [] stackTraceElement = e.getStackTrace();
	  if(stackTraceElement!=null&&stackTraceElement.length>0){
		  for(int i =0 ; i<stackTraceElement.length; i ++){
			  if(stackTraceElement[i]!=null){
				  strBuf.append("\r\n").append(stackTraceElement[i]);
				  }
			  }
		  } 
		   return strBuf.toString();
	 }
 
	
}
